package File_Test;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
public class test {
    public static void main(String[] args) throws IOException {
        File file = new File("1.txt");
        File galgame = new File("D:/galgame");
        File[] files = galgame.listFiles();
        HashMap<String, Integer> ret = Statistics_File("D:/File_Count");
        System.out.println(ret);
//        for(File f : files)
//        {
//            System.out.println(f.getName());
//        }
//        System.out.println(file.getAbsolutePath());
    }

    //统计目录下的文件类型及其个数
    public static HashMap<String, Integer> Statistics_File(String directoryPath){
        HashMap<String, Integer> ret =  new HashMap<>();
        File file = new File(directoryPath);
        File[] files = file.listFiles();
        for(File f : files)
        {
            String fileName = f.getName();
            int strlenth = fileName.length();
            int index = fileName.lastIndexOf(".");
            String file_Type = fileName.substring(index + 1, strlenth);
            if(!ret.containsKey(file_Type))
            {
                ret.put(fileName.substring(index + 1, strlenth), 1);
            }
            else
            {
                int count = ret.get(file_Type);
                ret.put(file_Type, count + 1);
            }
        }
        return ret;
    }
}
